home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / lib / mozilla-firefox / include / string / nsTSubstring.h < prev    next >
C/C++ Source or Header  |  2006-05-08  |  26KB  |  696 lines

  1. /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* vim:set ts=2 sw=2 sts=2 et cindent: */
  3. /* ***** BEGIN LICENSE BLOCK *****
  4.  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  5.  *
  6.  * The contents of this file are subject to the Mozilla Public License Version
  7.  * 1.1 (the "License"); you may not use this file except in compliance with
  8.  * the License. You may obtain a copy of the License at
  9.  * http://www.mozilla.org/MPL/
  10.  *
  11.  * Software distributed under the License is distributed on an "AS IS" basis,
  12.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  13.  * for the specific language governing rights and limitations under the
  14.  * License.
  15.  *
  16.  * The Original Code is Mozilla.
  17.  *
  18.  * The Initial Developer of the Original Code is IBM Corporation.
  19.  * Portions created by IBM Corporation are Copyright (C) 2003
  20.  * IBM Corporation. All Rights Reserved.
  21.  *
  22.  * Contributor(s):
  23.  *   Darin Fisher <darin@meer.net>
  24.  *
  25.  * Alternatively, the contents of this file may be used under the terms of
  26.  * either the GNU General Public License Version 2 or later (the "GPL"), or
  27.  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  28.  * in which case the provisions of the GPL or the LGPL are applicable instead
  29.  * of those above. If you wish to allow use of your version of this file only
  30.  * under the terms of either the GPL or the LGPL, and not to allow others to
  31.  * use your version of this file under the terms of the MPL, indicate your
  32.  * decision by deleting the provisions above and replace them with the notice
  33.  * and other provisions required by the GPL or the LGPL. If you do not delete
  34.  * the provisions above, a recipient may use your version of this file under
  35.  * the terms of any one of the MPL, the GPL or the LGPL.
  36.  *
  37.  * ***** END LICENSE BLOCK ***** */
  38.  
  39.  
  40.   /**
  41.    * nsTSubstring
  42.    *
  43.    * The base string type.  This type is not instantiated directly.  A sub-
  44.    * class is instantiated instead.  For example, see nsTString.
  45.    *
  46.    * This type works like nsTAString except that it does not have the ABI
  47.    * requirements of that interface.  Like nsTAString, nsTSubstring
  48.    * represents a single contiguous array of characters that may or may not
  49.    * be null-terminated.
  50.    *
  51.    * Many of the accessors on nsTSubstring are inlined as an optimization.
  52.    *
  53.    * This class is also known as "nsASingleFragmentC?String".
  54.    */
  55. class nsTSubstring_CharT : public nsTAString_CharT
  56.   {
  57.     public:
  58.  
  59.       typedef nsTSubstring_CharT    self_type;
  60.       typedef nsTString_CharT       string_type;
  61.  
  62.       typedef char_type*            char_iterator;
  63.       typedef const char_type*      const_char_iterator;
  64.  
  65. #ifdef MOZ_V1_STRING_ABI
  66.       typedef nsTAString_CharT      base_string_type;
  67. #else
  68.       typedef nsTSubstring_CharT    base_string_type;
  69. #endif
  70.  
  71.     public:
  72.  
  73. #ifndef MOZ_V1_STRING_ABI
  74.         // this acts like a virtual destructor
  75.       NS_COM NS_FASTCALL ~nsTSubstring_CharT();
  76. #endif
  77.  
  78.         /**
  79.          * reading iterators
  80.          */
  81.  
  82.       const_char_iterator BeginReading() const { return mData; }
  83.       const_char_iterator EndReading() const { return mData + mLength; }
  84.  
  85.         /**
  86.          * deprecated reading iterators
  87.          */
  88.  
  89.       const_iterator& BeginReading( const_iterator& iter ) const
  90.         {
  91.           iter.mStart = mData;
  92.           iter.mEnd = mData + mLength;
  93.           iter.mPosition = iter.mStart;
  94.           return iter;
  95.         }
  96.  
  97.       const_iterator& EndReading( const_iterator& iter ) const
  98.         {
  99.           iter.mStart = mData;
  100.           iter.mEnd = mData + mLength;
  101.           iter.mPosition = iter.mEnd;
  102.           return iter;
  103.         }
  104.  
  105.       const_char_iterator& BeginReading( const_char_iterator& iter ) const
  106.         {
  107.           return iter = mData;
  108.         }
  109.  
  110.       const_char_iterator& EndReading( const_char_iterator& iter ) const
  111.         {
  112.           return iter = mData + mLength;
  113.         }
  114.  
  115.  
  116.         /**
  117.          * writing iterators
  118.          */
  119.       
  120.       char_iterator BeginWriting() { EnsureMutable(); return mData; }
  121.       char_iterator EndWriting() { EnsureMutable(); return mData + mLength; }
  122.  
  123.         /**
  124.          * deprecated writing iterators
  125.          */
  126.       
  127.       iterator& BeginWriting( iterator& iter )
  128.         {
  129.           EnsureMutable();
  130.           iter.mStart = mData;
  131.           iter.mEnd = mData + mLength;
  132.           iter.mPosition = iter.mStart;
  133.           return iter;
  134.         }
  135.  
  136.       iterator& EndWriting( iterator& iter )
  137.         {
  138.           EnsureMutable();
  139.           iter.mStart = mData;
  140.           iter.mEnd = mData + mLength;
  141.           iter.mPosition = iter.mEnd;
  142.           return iter;
  143.         }
  144.  
  145.       char_iterator& BeginWriting( char_iterator& iter )
  146.         {
  147.           EnsureMutable();
  148.           return iter = mData;
  149.         }
  150.  
  151.       char_iterator& EndWriting( char_iterator& iter )
  152.         {
  153.           EnsureMutable();
  154.           return iter = mData + mLength;
  155.         }
  156.  
  157.  
  158.         /**
  159.          * accessors
  160.          */
  161.  
  162.         // returns pointer to string data (not necessarily null-terminated)
  163.       const char_type *Data() const
  164.         {
  165.           return mData;
  166.         }
  167.  
  168.       size_type Length() const
  169.         {
  170.           return mLength;
  171.         }
  172.  
  173.       PRBool IsEmpty() const
  174.         {
  175.           return mLength == 0;
  176.         }
  177.  
  178.       PRBool IsVoid() const
  179.         {
  180.           return mFlags & F_VOIDED;
  181.         }
  182.  
  183.       PRBool IsTerminated() const
  184.         {
  185.           return mFlags & F_TERMINATED;
  186.         }
  187.  
  188.       char_type CharAt( index_type i ) const
  189.         {
  190.           NS_ASSERTION(i < mLength, "index exceeds allowable range");
  191.           return mData[i];
  192.         }
  193.  
  194.       char_type operator[]( index_type i ) const
  195.         {
  196.           return CharAt(i);
  197.         }
  198.  
  199.       char_type First() const
  200.         {
  201.           NS_ASSERTION(mLength > 0, "|First()| called on an empty string");
  202.           return mData[0];
  203.         }
  204.  
  205.       inline
  206.       char_type Last() const
  207.         {
  208.           NS_ASSERTION(mLength > 0, "|Last()| called on an empty string");
  209.           return mData[mLength - 1];
  210.         }
  211.  
  212.       NS_COM size_type NS_FASTCALL CountChar( char_type ) const;
  213.       NS_COM PRInt32 NS_FASTCALL FindChar( char_type, index_type offset = 0 ) const;
  214.  
  215.  
  216.         /**
  217.          * equality
  218.          */
  219.  
  220.       NS_COM PRBool NS_FASTCALL Equals( const self_type& ) const;
  221.       NS_COM PRBool NS_FASTCALL Equals( const self_type&, const comparator_type& ) const;
  222.  
  223. #ifdef MOZ_V1_STRING_ABI
  224.       NS_COM PRBool NS_FASTCALL Equals( const abstract_string_type& readable ) const;
  225.       NS_COM PRBool NS_FASTCALL Equals( const abstract_string_type& readable, const comparator_type& comp ) const;
  226. #endif
  227.  
  228.       NS_COM PRBool NS_FASTCALL Equals( const char_type* data ) const;
  229.       NS_COM PRBool NS_FASTCALL Equals( const char_type* data, const comparator_type& comp ) const;
  230.  
  231.         /**
  232.          * An efficient comparison with ASCII that can be used even
  233.          * for wide strings. Call this version when you know the
  234.          * length of 'data'.
  235.          */
  236.       NS_COM PRBool NS_FASTCALL EqualsASCII( const char* data, size_type len ) const;
  237.         /**
  238.          * An efficient comparison with ASCII that can be used even
  239.          * for wide strings. Call this version when 'data' is
  240.          * null-terminated.
  241.          */
  242.       NS_COM PRBool NS_FASTCALL EqualsASCII( const char* data ) const;
  243.  
  244.     // EqualsLiteral must ONLY be applied to an actual literal string.
  245.     // Do not attempt to use it with a regular char* pointer, or with a char
  246.     // array variable.
  247.     // The template trick to acquire the array length at compile time without
  248.     // using a macro is due to Corey Kosak, with much thanks.
  249. #ifdef NS_DISABLE_LITERAL_TEMPLATE
  250.       inline PRBool EqualsLiteral( const char* str ) const
  251.         {
  252.           return EqualsASCII(str);
  253.         }
  254. #else
  255.       template<int N>
  256.       inline PRBool EqualsLiteral( const char (&str)[N] ) const
  257.         {
  258.           return EqualsASCII(str, N-1);
  259.         }
  260.       template<int N>
  261.       inline PRBool EqualsLiteral( char (&str)[N] ) const
  262.         {
  263.           const char* s = str;
  264.           return EqualsASCII(s, N-1);
  265.         }
  266. #endif
  267.  
  268.     // The LowerCaseEquals methods compare the lower case version of
  269.     // this string to some ASCII/Literal string. The ASCII string is
  270.     // *not* lowercased for you. If you compare to an ASCII or literal
  271.     // string that contains an uppercase character, it is guaranteed to
  272.     // return false. We will throw assertions too.
  273.       NS_COM PRBool NS_FASTCALL LowerCaseEqualsASCII( const char* data, size_type len ) const;
  274.       NS_COM PRBool NS_FASTCALL LowerCaseEqualsASCII( const char* data ) const;
  275.  
  276.     // LowerCaseEqualsLiteral must ONLY be applied to an actual
  277.     // literal string.  Do not attempt to use it with a regular char*
  278.     // pointer, or with a char array variable. Use
  279.     // LowerCaseEqualsASCII for them.
  280. #ifdef NS_DISABLE_LITERAL_TEMPLATE
  281.       inline PRBool LowerCaseEqualsLiteral( const char* str ) const
  282.         {
  283.           return LowerCaseEqualsASCII(str);
  284.         }
  285. #else
  286.       template<int N>
  287.       inline PRBool LowerCaseEqualsLiteral( const char (&str)[N] ) const
  288.         {
  289.           return LowerCaseEqualsASCII(str, N-1);
  290.         }
  291.       template<int N>
  292.       inline PRBool LowerCaseEqualsLiteral( char (&str)[N] ) const
  293.         {
  294.           const char* s = str;
  295.           return LowerCaseEqualsASCII(s, N-1);
  296.         }
  297. #endif
  298.  
  299.         /**
  300.          * assignment
  301.          */
  302.  
  303.       void Assign( char_type c )                                                                { Assign(&c, 1); }
  304.       NS_COM void NS_FASTCALL Assign( const char_type* data, size_type length = size_type(-1) );
  305.       NS_COM void NS_FASTCALL Assign( const self_type& );
  306.       NS_COM void NS_FASTCALL Assign( const substring_tuple_type& );
  307. #ifdef MOZ_V1_STRING_ABI
  308.       NS_COM void NS_FASTCALL Assign( const abstract_string_type& );
  309. #endif
  310.  
  311.       NS_COM void NS_FASTCALL AssignASCII( const char* data, size_type length );
  312.       NS_COM void NS_FASTCALL AssignASCII( const char* data );
  313.  
  314.     // AssignLiteral must ONLY be applied to an actual literal string.
  315.     // Do not attempt to use it with a regular char* pointer, or with a char
  316.     // array variable. Use AssignASCII for those.
  317. #ifdef NS_DISABLE_LITERAL_TEMPLATE
  318.       void AssignLiteral( const char* str )
  319.                   { AssignASCII(str); }
  320. #else
  321.       template<int N>
  322.       void AssignLiteral( const char (&str)[N] )
  323.                   { AssignASCII(str, N-1); }
  324.       template<int N>
  325.       void AssignLiteral( char (&str)[N] )
  326.                   { AssignASCII(str, N-1); }
  327. #endif
  328.  
  329.       self_type& operator=( char_type c )                                                       { Assign(c);        return *this; }
  330.       self_type& operator=( const char_type* data )                                             { Assign(data);     return *this; }
  331.       self_type& operator=( const self_type& str )                                              { Assign(str);      return *this; }
  332.       self_type& operator=( const substring_tuple_type& tuple )                                 { Assign(tuple);    return *this; }
  333. #ifdef MOZ_V1_STRING_ABI
  334.       self_type& operator=( const abstract_string_type& readable )                              { Assign(readable); return *this; }
  335. #endif
  336.  
  337.       NS_COM void NS_FASTCALL Adopt( char_type* data, size_type length = size_type(-1) );
  338.  
  339.  
  340.         /**
  341.          * buffer manipulation
  342.          */
  343.  
  344.              void Replace( index_type cutStart, size_type cutLength, char_type c )               { Replace(cutStart, cutLength, &c, 1); }
  345.       NS_COM void NS_FASTCALL Replace( index_type cutStart, size_type cutLength, const char_type* data, size_type length = size_type(-1) );
  346.              void Replace( index_type cutStart, size_type cutLength, const self_type& str )      { Replace(cutStart, cutLength, str.Data(), str.Length()); }
  347.       NS_COM void NS_FASTCALL Replace( index_type cutStart, size_type cutLength, const substring_tuple_type& tuple );
  348. #ifdef MOZ_V1_STRING_ABI
  349.       NS_COM void NS_FASTCALL Replace( index_type cutStart, size_type cutLength, const abstract_string_type& readable );
  350. #endif
  351.  
  352.       NS_COM void NS_FASTCALL ReplaceASCII( index_type cutStart, size_type cutLength, const char* data, size_type length = size_type(-1) );
  353.  
  354.       void Append( char_type c )                                                                 { Replace(mLength, 0, c); }
  355.       void Append( const char_type* data, size_type length = size_type(-1) )                     { Replace(mLength, 0, data, length); }
  356.       void Append( const self_type& str )                                                        { Replace(mLength, 0, str); }
  357.       void Append( const substring_tuple_type& tuple )                                           { Replace(mLength, 0, tuple); }
  358. #ifdef MOZ_V1_STRING_ABI
  359.       void Append( const abstract_string_type& readable )                                        { Replace(mLength, 0, readable); }
  360. #endif
  361.  
  362.       void AppendASCII( const char* data, size_type length = size_type(-1) )                     { ReplaceASCII(mLength, 0, data, length); }
  363.  
  364.     // AppendLiteral must ONLY be applied to an actual literal string.
  365.     // Do not attempt to use it with a regular char* pointer, or with a char
  366.     // array variable. Use AppendASCII for those.
  367. #ifdef NS_DISABLE_LITERAL_TEMPLATE
  368.       void AppendLiteral( const char* str )
  369.                   { AppendASCII(str); }
  370. #else
  371.       template<int N>
  372.       void AppendLiteral( const char (&str)[N] )
  373.                   { AppendASCII(str, N-1); }
  374.       template<int N>
  375.       void AppendLiteral( char (&str)[N] )
  376.                   { AppendASCII(str, N-1); }
  377. #endif
  378.  
  379.       self_type& operator+=( char_type c )                                                       { Append(c);        return *this; }
  380.       self_type& operator+=( const char_type* data )                                             { Append(data);     return *this; }
  381.       self_type& operator+=( const self_type& str )                                              { Append(str);      return *this; }
  382.       self_type& operator+=( const substring_tuple_type& tuple )                                 { Append(tuple);    return *this; }
  383. #ifdef MOZ_V1_STRING_ABI
  384.       self_type& operator+=( const abstract_string_type& readable )                              { Append(readable); return *this; }
  385. #endif
  386.  
  387.       void Insert( char_type c, index_type pos )                                                 { Replace(pos, 0, c); }
  388.       void Insert( const char_type* data, index_type pos, size_type length = size_type(-1) )     { Replace(pos, 0, data, length); }
  389.       void Insert( const self_type& str, index_type pos )                                        { Replace(pos, 0, str); }
  390.       void Insert( const substring_tuple_type& tuple, index_type pos )                           { Replace(pos, 0, tuple); }
  391. #ifdef MOZ_V1_STRING_ABI
  392.       void Insert( const abstract_string_type& readable, index_type pos )                        { Replace(pos, 0, readable); }
  393. #endif
  394.  
  395.       void Cut( index_type cutStart, size_type cutLength )                                       { Replace(cutStart, cutLength, char_traits::sEmptyBuffer, 0); }
  396.  
  397.  
  398.         /**
  399.          * buffer sizing
  400.          */
  401.  
  402.       NS_COM void NS_FASTCALL SetCapacity( size_type capacity );
  403.  
  404.       NS_COM void NS_FASTCALL SetLength( size_type );
  405.  
  406.       void Truncate( size_type newLength = 0 )
  407.         {
  408.           NS_ASSERTION(newLength <= mLength, "Truncate cannot make string longer");
  409.           SetLength(newLength);
  410.         }
  411.  
  412.  
  413.         /**
  414.          * string data is never null, but can be marked void.  if true, the
  415.          * string will be truncated.  @see nsTSubstring::IsVoid
  416.          */
  417.  
  418.       NS_COM void NS_FASTCALL SetIsVoid( PRBool );
  419.  
  420.         /**
  421.          *  This method is used to remove all occurances of aChar from this
  422.          * string.
  423.          *  
  424.          *  @param  aChar -- char to be stripped
  425.          *  @param  aOffset -- where in this string to start stripping chars
  426.          */
  427.          
  428.       NS_COM void StripChar( char_type aChar, PRInt32 aOffset=0 );
  429.  
  430.  
  431.     public:
  432.  
  433.         /**
  434.          * this is public to support automatic conversion of tuple to string
  435.          * base type, which helps avoid converting to nsTAString.
  436.          */
  437.       nsTSubstring_CharT(const substring_tuple_type& tuple)
  438. #ifdef MOZ_V1_STRING_ABI
  439.         : abstract_string_type(nsnull, 0, F_NONE)
  440. #else
  441.         : mData(nsnull),
  442.           mLength(0),
  443.           mFlags(F_NONE)
  444. #endif
  445.         {
  446.           Assign(tuple);
  447.         }
  448.  
  449.         /**
  450.          * allows for direct initialization of a nsTSubstring object. 
  451.          *
  452.          * NOTE: this constructor is declared public _only_ for convenience
  453.          * inside the string implementation.
  454.          */
  455.       nsTSubstring_CharT( char_type *data, size_type length, PRUint32 flags )
  456. #ifdef MOZ_V1_STRING_ABI
  457.         : abstract_string_type(data, length, flags) {}
  458. #else
  459.         : mData(data),
  460.           mLength(length),
  461.           mFlags(flags) {}
  462. #endif
  463.  
  464.  
  465.     protected:
  466.  
  467.       friend class nsTObsoleteAStringThunk_CharT;
  468.       friend class nsTAString_CharT;
  469.       friend class nsTSubstringTuple_CharT;
  470.  
  471.       // XXX GCC 3.4 needs this :-(
  472.       friend class nsTPromiseFlatString_CharT;
  473.  
  474. #ifndef MOZ_V1_STRING_ABI
  475.       char_type*  mData;
  476.       size_type   mLength;
  477.       PRUint32    mFlags;
  478. #endif
  479.  
  480.         // default initialization 
  481.       nsTSubstring_CharT()
  482. #ifdef MOZ_V1_STRING_ABI
  483.         : abstract_string_type(
  484.               NS_CONST_CAST(char_type*, char_traits::sEmptyBuffer), 0, F_TERMINATED) {}
  485. #else
  486.         : mData(NS_CONST_CAST(char_type*, char_traits::sEmptyBuffer)),
  487.           mLength(0),
  488.           mFlags(F_TERMINATED) {}
  489. #endif
  490.  
  491.         // version of constructor that leaves mData and mLength uninitialized
  492.       explicit
  493.       nsTSubstring_CharT( PRUint32 flags )
  494. #ifdef MOZ_V1_STRING_ABI
  495.         : abstract_string_type(flags) {}
  496. #else
  497.         : mFlags(flags) {}
  498. #endif
  499.  
  500.         // copy-constructor, constructs as dependent on given object
  501.         // (NOTE: this is for internal use only)
  502.       nsTSubstring_CharT( const self_type& str )
  503. #ifdef MOZ_V1_STRING_ABI
  504.         : abstract_string_type(str.mData, str.mLength, str.mFlags & (F_TERMINATED | F_VOIDED)) {}
  505. #else
  506.         : mData(str.mData),
  507.           mLength(str.mLength),
  508.           mFlags(str.mFlags & (F_TERMINATED | F_VOIDED)) {}
  509. #endif
  510.  
  511.         /**
  512.          * this function releases mData and does not change the value of
  513.          * any of its member variables.  inotherwords, this function acts
  514.          * like a destructor.
  515.          */
  516.       void NS_FASTCALL Finalize();
  517.  
  518.         /**
  519.          * this function prepares mData to be mutated.
  520.          *
  521.          * @param capacity     specifies the required capacity of mData  
  522.          * @param old_data     returns null or the old value of mData
  523.          * @param old_flags    returns 0 or the old value of mFlags
  524.          *
  525.          * if mData is already mutable and of sufficient capacity, then this
  526.          * function will return immediately.  otherwise, it will either resize
  527.          * mData or allocate a new shared buffer.  if it needs to allocate a
  528.          * new buffer, then it will return the old buffer and the corresponding
  529.          * flags.  this allows the caller to decide when to free the old data.
  530.          *
  531.          * this function returns false if is unable to allocate sufficient
  532.          * memory.
  533.          *
  534.          * XXX we should expose a way for subclasses to free old_data.
  535.          */
  536.       PRBool NS_FASTCALL MutatePrep( size_type capacity, char_type** old_data, PRUint32* old_flags );
  537.  
  538.         /**
  539.          * this function prepares a section of mData to be modified.  if
  540.          * necessary, this function will reallocate mData and possibly move
  541.          * existing data to open up the specified section.
  542.          *
  543.          * @param cutStart     specifies the starting offset of the section
  544.          * @param cutLength    specifies the length of the section to be replaced
  545.          * @param newLength    specifies the length of the new section
  546.          *
  547.          * for example, suppose mData contains the string "abcdef" then
  548.          * 
  549.          *   ReplacePrep(2, 3, 4);
  550.          *
  551.          * would cause mData to look like "ab____f" where the characters
  552.          * indicated by '_' have an unspecified value and can be freely
  553.          * modified.  this function will null-terminate mData upon return.
  554.          * 
  555.          * this function returns false if is unable to allocate sufficient
  556.          * memory.
  557.          */
  558.       PRBool NS_FASTCALL ReplacePrep( index_type cutStart, size_type cutLength, size_type newLength );
  559.  
  560.         /**
  561.          * returns the number of writable storage units starting at mData.
  562.          * the value does not include space for the null-terminator character.
  563.          *
  564.          * NOTE: this function returns size_type(-1) if mData is immutable.
  565.          */
  566.       size_type NS_FASTCALL Capacity() const;
  567.  
  568.         /**
  569.          * this helper function can be called prior to directly manipulating
  570.          * the contents of mData.  see, for example, BeginWriting.
  571.          */
  572.       NS_COM void NS_FASTCALL EnsureMutable();
  573.  
  574.         /**
  575.          * returns true if this string overlaps with the given string fragment.
  576.          */
  577.       PRBool IsDependentOn( const char_type *start, const char_type *end ) const
  578.         {
  579.           /**
  580.            * if it _isn't_ the case that one fragment starts after the other ends,
  581.            * or ends before the other starts, then, they conflict:
  582.            * 
  583.            *   !(f2.begin >= f1.end || f2.end <= f1.begin)
  584.            * 
  585.            * Simplified, that gives us:
  586.            */
  587.           return ( start < (mData + mLength) && end > mData );
  588.         }
  589.  
  590.         /**
  591.          * this helper function stores the specified dataFlags in mFlags
  592.          */
  593.       void SetDataFlags(PRUint32 dataFlags)
  594.         {
  595.           NS_ASSERTION((dataFlags & 0xFFFF0000) == 0, "bad flags");
  596.           mFlags = dataFlags | (mFlags & 0xFFFF0000);
  597.         }
  598.  
  599.     public:
  600.  
  601.       // mFlags is a bitwise combination of the following flags.  the meaning
  602.       // and interpretation of these flags is an implementation detail.
  603.       // 
  604.       // NOTE: these flags are declared public _only_ for convenience inside
  605.       // the string implementation.
  606.       
  607.       enum
  608.         {
  609.           F_NONE         = 0,       // no flags
  610.  
  611.           // data flags are in the lower 16-bits
  612.           F_TERMINATED   = 1 << 0,  // IsTerminated returns true
  613.           F_VOIDED       = 1 << 1,  // IsVoid returns true
  614.           F_SHARED       = 1 << 2,  // mData points to a heap-allocated, shared buffer
  615.           F_OWNED        = 1 << 3,  // mData points to a heap-allocated, raw buffer
  616.           F_FIXED        = 1 << 4,  // mData points to a fixed-size writable, dependent buffer
  617.  
  618.           // class flags are in the upper 16-bits
  619.           F_CLASS_FIXED  = 1 << 16   // indicates that |this| is of type nsTFixedString
  620.         };
  621.  
  622.       //
  623.       // Some terminology:
  624.       //
  625.       //   "dependent buffer"    A dependent buffer is one that the string class
  626.       //                         does not own.  The string class relies on some
  627.       //                         external code to ensure the lifetime of the
  628.       //                         dependent buffer.
  629.       //
  630.       //   "shared buffer"       A shared buffer is one that the string class
  631.       //                         allocates.  When it allocates a shared string
  632.       //                         buffer, it allocates some additional space at
  633.       //                         the beginning of the buffer for additional 
  634.       //                         fields, including a reference count and a 
  635.       //                         buffer length.  See nsStringHeader.
  636.       //                         
  637.       //   "adopted buffer"      An adopted buffer is a raw string buffer
  638.       //                         allocated on the heap (using nsMemory::Alloc)
  639.       //                         of which the string class subsumes ownership.
  640.       //
  641.       // Some comments about the string flags:
  642.       //
  643.       //   F_SHARED, F_OWNED, and F_FIXED are all mutually exlusive.  They
  644.       //   indicate the allocation type of mData.  If none of these flags
  645.       //   are set, then the string buffer is dependent.
  646.       //
  647.       //   F_SHARED, F_OWNED, or F_FIXED imply F_TERMINATED.  This is because
  648.       //   the string classes always allocate null-terminated buffers, and
  649.       //   non-terminated substrings are always dependent.
  650.       //
  651.       //   F_VOIDED implies F_TERMINATED, and moreover it implies that mData
  652.       //   points to char_traits::sEmptyBuffer.  Therefore, F_VOIDED is
  653.       //   mutually exclusive with F_SHARED, F_OWNED, and F_FIXED.
  654.       //
  655.   };
  656.  
  657. NS_COM
  658. int NS_FASTCALL Compare( const nsTSubstring_CharT::base_string_type& lhs, const nsTSubstring_CharT::base_string_type& rhs, const nsTStringComparator_CharT& = nsTDefaultStringComparator_CharT() );
  659.  
  660.  
  661. inline
  662. PRBool operator!=( const nsTSubstring_CharT::base_string_type& lhs, const nsTSubstring_CharT::base_string_type& rhs )
  663.   {
  664.     return !lhs.Equals(rhs);
  665.   }
  666.  
  667. inline
  668. PRBool operator< ( const nsTSubstring_CharT::base_string_type& lhs, const nsTSubstring_CharT::base_string_type& rhs )
  669.   {
  670.     return Compare(lhs, rhs)< 0;
  671.   }
  672.  
  673. inline
  674. PRBool operator<=( const nsTSubstring_CharT::base_string_type& lhs, const nsTSubstring_CharT::base_string_type& rhs )
  675.   {
  676.     return Compare(lhs, rhs)<=0;
  677.   }
  678.  
  679. inline
  680. PRBool operator==( const nsTSubstring_CharT::base_string_type& lhs, const nsTSubstring_CharT::base_string_type& rhs )
  681.   {
  682.     return lhs.Equals(rhs);
  683.   }
  684.  
  685. inline
  686. PRBool operator>=( const nsTSubstring_CharT::base_string_type& lhs, const nsTSubstring_CharT::base_string_type& rhs )
  687.   {
  688.     return Compare(lhs, rhs)>=0;
  689.   }
  690.  
  691. inline
  692. PRBool operator> ( const nsTSubstring_CharT::base_string_type& lhs, const nsTSubstring_CharT::base_string_type& rhs )
  693.   {
  694.     return Compare(lhs, rhs)> 0;
  695.   }
  696.